/*
 * @lc app=leetcode.cn id=500 lang=rust
 *
 * [500] 键盘行
 */

// @lc code=start
impl Solution {
    pub fn find_words(words: Vec<String>) -> Vec<String> {
        use std::collections::HashSet;
        let s0: HashSet<char> = vec!['q','w','e','r','t','y','u','i','o','p'].drain(..).collect();
        let s1: HashSet<char> = vec!['a','s','d','f','g','h','j','k','l'].drain(..).collect();
        let s2: HashSet<char> = vec!['z','x','c','v','b','n','m'].drain(..).collect();
        let s = vec![s0, s1, s2];
        let mut ret = Vec::new();

        for w in words.iter() {
            let word = w.clone().to_lowercase();

            let mut inx = 0;
            for i in 0..3{
                if s[i].contains(&word.chars().nth(0).unwrap()) {
                    inx = i;
                    break;
                }
            }
            let mut flag = true;
            for i in word.chars() {
                if !s[inx].contains(&i) {
                    flag = false;
                    break;
                }
            }
            if flag {
                ret.push(w.to_string());
            }
        }
        return ret;
    }
}
// @lc code=end

